﻿Imports System.Data.OleDb

Public Class addRecipe
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Add_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Add.Click

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString + ".jpg"

        If f_Photo.HasFile Then
            Dim photoLocation = Request.MapPath("photos") & "/" & newFileName
            f_Photo.SaveAs(photoLocation)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("mbrConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into recipes(RecipeName,Rating,CookingTime,ShortDescription,Ingredients,CookingMethod,Photo,RecipeSource) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_RecipeName.Text)
        cmd.Parameters.AddWithValue("@f2", rbl_Rating.SelectedValue)
        cmd.Parameters.AddWithValue("@f3", tb_CookingTime.Text)
        cmd.Parameters.AddWithValue("@f4", tb_ShortDescription.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Ingredients.Text)
        cmd.Parameters.AddWithValue("@f6", tb_CookingMethod.Text)
        cmd.Parameters.AddWithValue("@f7", "photos/" & newFileName)
        cmd.Parameters.AddWithValue("@f8", tb_RecipeSource.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub

    Protected Sub tb_CookingTime_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles tb_CookingTime.TextChanged

    End Sub
End Class